package com.kakavr.shop.service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang3.math.NumberUtils;
import org.joda.time.DateTime;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.kakavr.base.service.BaseService;
import com.kakavr.page.Pagination;
import com.kakavr.page.constant.PaginationConstant;
import com.kakavr.shop.dao.ITradeFlowDao;
import com.kakavr.util.DateTimeUtils;
@Service
public class TradeFlowService extends BaseService implements ITradeFlowService {
	@Resource
	private ITradeFlowDao tradeFlowDao;

	@Override
	public void addTradeFlow(Map<String, Object> map) {
		map.put("createTime", DateTime.now().toDate());
		tradeFlowDao.insertTradeFlow(map);
	}
	@Override
	public void addActivityTradeFlow(Map<String,Object> map) {
		map.put("type", 3);
		map.put("category", 1);
		map.put("rechargeId", 0);//不是充值
		this.addTradeFlow(map);
	}

	@Override
	public Pagination<Map<String, Object>> selectTradeFlowList(
			Map<String, Object> map) {
		PageHelper.startPage(NumberUtils.toInt((String) map
				.get(PaginationConstant.PAGE_NO_NAME)), NumberUtils
				.toInt((String) map.get(PaginationConstant.PAGE_SIZE_NAME)));
		return new Pagination<Map<String,Object>>(tradeFlowDao.selectTradeFlowList(map));
	}
	
	@Override
	public List<Map<String, Object>> statisActivityTradeFlowList(
			Map<String, Object> map) {
		map.put("createTime",DateTimeUtils.getThisWeekMonday(new Date()));//获取本周一的时间
		return tradeFlowDao.statisActivityTradeFlowList(map);
	}

	@Override
	public List<Map<String, Object>> statisticsTradeFlow(Map<String, Object> map) {
		return tradeFlowDao.statisticsTradeFlow(map);
	}
	
	@Override
	public void updateTradeFlow(Map<String, Object> map) {
		map.put("createTime", DateTimeUtils.getThisWeekMonday(new Date()));
		tradeFlowDao.updateTradeFlow(map);
	}

}
